﻿#ifndef GAMEWIN_H
#define GAMEWIN_H

#include <QWidget>
#include <QGraphicsView>
#include <QList>
#include <QDebug>
#include <QTimer>
#include <QMediaPlayer>
#include <QMediaPlaylist>
#include <QTcpSocket>

class GameSce;
class Button;
class Card;
class QParallelAnimationGroup;
class QSequentialAnimationGroup;
class Board;
class GameManager;
class GameManagerOnline;
class PlayerInfo;
class dialogOnline;

namespace Ui {
class GameWin;
}

class GameWin : public QWidget
{
    Q_OBJECT

public:
    explicit GameWin(QWidget *parent = 0);
    ~GameWin();

public:
    void initControl();
    void initMusic();
    void initWelcome();
    void initHelp();
    void initGame();
    void initCard();
    void paintEvent(QPaintEvent* event);
    void switchTOhelp();
    void switchTOgame();
    void switchTOwelcome();
    void switchToHall_ol(); // 转移到联机大厅
    void tcpDown();
    void tcpUse(QString tempStr);
    void switchTOgame_ol(); // 转移到线上游戏
    void tcpUp(QByteArray bt);

public:
    void offline_normal();
    void offline_demonic();
    void online_normal();
    void online_demonic();

private:
    Ui::GameWin *ui;
    GameSce* m_scene; // 主页场景
    GameSce* m_sceneHelp,* m_sceneGame; // 说明场景、游戏场景
    QGraphicsView* m_View;
    Button* m_buttonStart,* m_buttonHelp,* m_buttonExit; // 主页按钮
    Button* m_buttonBack_help,* m_buttonBack_game; // 返回按钮
    Board* m_board; // 棋盘
    GameManager* m_manager; // 管理器
    GameManagerOnline* m_manager_ol;
    PlayerInfo* playerInfo;
    QTcpSocket* m_tcpSocket;
    bool m_isOnline = false;

    // 卡牌
    Card* m_cardElephant_red,* m_cardTiger_red,* m_cardLion_red,* m_cardCheetah_red;
    Card* m_cardWolf_red,* m_cardDog_red,* m_cardCat_red,* m_cardRat_red;
    Card* m_cardElephant_blue,* m_cardTiger_blue,* m_cardLion_blue,* m_cardCheetah_blue;
    Card* m_cardWolf_blue,* m_cardDog_blue,* m_cardCat_blue,* m_cardRat_blue;
    QList<Card*> m_cardList; // 用于管理卡牌的链表
    QList<QPixmap* > m_faceList_red;
    QList<QPixmap* > m_faceList_blue;

    QParallelAnimationGroup* Game_Start; // (单机)游戏开始动画
    QParallelAnimationGroup* Online_Start; // (联机)游戏开始动画


    // 计时器
    QTimer* m_startTimer;

public:
    // 音乐播放器
    QMediaPlayer* m_welcomeBgm; // 欢迎界面音乐
    QMediaPlayer* m_gameBgm; // 游戏界面音乐
    QMediaPlaylist* m_welcomeList; // 欢迎界面音乐播放列表
    QMediaPlaylist* m_gameList; // 游戏界面音乐播放列表

signals:
    void cardReady(); // 卡牌工作已准备完毕

};

#endif // GAMEWIN_H
